import React, { Component} from 'react';
import '../../Stylesheets/wx/agent.css'
import {NextStatisInfo} from '../../Action/auth';

export default class AgentCom extends Component {
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            nextInfoList:[],
            showAgent:false
        };
    }

/*
    componentDidMount() {
        this.getNextInfo()
    }
*/

    //获取下级代理个数
    async getNextInfo(id){
        await NextStatisInfo(id)
            .then(res=>{
                this.setState({nextInfoList:res})
            })
            .catch(err=>{
                console.warn('获取信息失败',err)
            })
        /*this.setState({nextInfoList:[{image_uri:require('../../Images/common/related.png'),member_name:'哈哈',agent_desc:'78',countAcc:'5'},
        {image_uri:require('../../Images/common/related.png'),member_name:'呵呵',agent_desc:'16',countAcc:'5'},
        {image_uri:require('../../Images/common/related.png'),member_name:'呦呦',agent_desc:'24',countAcc:'5'}]})*/
        this.setState({showAgent:!this.state.showAgent})
    }


    render(){
        const {nextInfoList} = this.state
        const {agentDetail,data,num} = this.props
        return(
            <div>
                <div
                    className="pay_padd flex flex-pack-justify border_bottom f14"
                    onClick = {()=>this.getNextInfo(data.acc_id)}
                    style={{paddingLeft:(6-num)*20}}
                >
                    <span style={{marginLeft:10}}>
                        <img src={data.image_uri} alt="" style={{ width: 20,height: 20,borderRadius:'50%',marginRight:10}}/>
                        {data.member_name}({data.agent_desc})
                    </span>
                    <span className="circle">{data.countAcc}</span>
                </div>
                {
                    nextInfoList&&nextInfoList.map(item=>{
                        return(
                            this.state.showAgent?
                                <AgentCom
                                    num = {num-1}
                                    data={item}
                                />
                            :null
                        )
                    })
                }
            </div>
        )
    }

}